<%@page import="cn.kgc.util.Pages"%>
<%@page import="cn.kgc.entity.Detail"%>
<%@page import="java.util.List"%>
<%@page import="cn.kgc.service.impl.NewsServiceImpl"%>
<%@page import="cn.kgc.service.NewsService"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>无标题文档</title>
	<link type="text/css" rel="stylesheet"
		href="<%=request.getContextPath()%>/css/common.css" />
	<style type="text/css">
<!--
-->
</style>
	<script>
		function addNews() {
			window.location = "newsDetailCreateSimple.jsp";
		}
	
	</script>
</head>

<body>
	<a href="<c:url value='http://www.baidu.com'/>"> 此链接由jstl表达式提供 </a>
	<!--主体-->
	<!--即时新闻-->
	<div class="main-text-box">
		<div class="main-text-box-tbg">
			<div class="main-text-box-bbg">
				<form name="searchForm" id="searchForm"
					action="<%=request.getContextPath()%>/admin/newsDetailList.jsp"
					method="post">
					<div>
						新闻分类： <select name="categoryId">
							<option value="0">全部</option>

							<option value='1'>国内</option>

							<option value='2'>国际</option>

							<option value='3'>娱乐</option>

							<option value='4'>军事</option>

							<option value='5'>财经</option>

							<option value='6'>天气</option>

						</select> 新闻标题<input type="text" name="title" id="title" value='' />
						<button type="submit" class="page-btn">GO</button>
						<button type="button" onclick="addNews();" class="page-btn">增加</button>
						<input type="hidden" name="currentPagnNo" value="1" /> <input
							type="hidden" name="pageSize" value="10" /> <input type="hidden"
							name="totalPageCount" value="2" />
					</div>
				</form>
				<table cellpadding="1" cellspacing="1" class="admin-list">
					<thead>
						<tr class="admin-list-head">
							<th>新闻标题</th>
							<th>作者</th>
							<th>时间</th>
							<th>操作</th>
						</tr>
					</thead>
					<!-- class="admin-list-td-h2" -->
					<tbody>
						<%
							NewsService service = new NewsServiceImpl();
							Pages pages = new Pages();
							//设置页码
							String current = request.getParameter("currentPagnNo");
							//如果current是 空的则表示用户是第一次点开此页面，然后赋一个值
							if (current == null || current == "") {
								current = "1";
							}
							int currentPageNo = Integer.parseInt(current);
							//设置每页的容量
							int pageSize = 3;
							pages.setPageSize(pageSize);
							//获取新闻的总条数
							int totalCount = service.getNewsCount();
							pages.setTotalCount(totalCount);
							int totalPageCount = pages.getTotalPageCount();
							pages.setCurrentPageNo(currentPageNo);
							List<Detail> news = service.getNewsForPage(pages.getCurrentPageNo(), pages.getPageSize(),
									pages.getTotalPageCount());
							int i = 0;
							//将pages放入请求域中
							request.setAttribute("pages", pages);
							request.setAttribute("news", news);
						%>
						<c:forEach items="${news }" var="news" varStatus="statu">
							<tr
								<c:if test="${statu.count%2==0 }"> class="admin-list-td-h2"</c:if>>
								<td><a href='newsDetailView.jsp?id=${news.id }'><c:out
											value="${news.title}" escapeXml="true" /></a></td>
								<td>${news.author }</td>
								<td> <fmt:formatDate value="${news.createDate }" pattern="yyyy-MM-dd"/> </td>
								<td><a href='adminNewsCreate.jsp?id=2'>修改</a> 
								<a href="javascript:if(confirm('确认是否删除此新闻？')) location='<%=request.getContextPath() %>/servlet/DeleteServlet?id=${news.id }'">删除</a>
								</td>
							</tr>
						</c:forEach>

					</tbody>
				</table>
				<!-- 向目标页传数据 -->
				<c:import url="rollpage.jsp">
					<c:param name="totalCount" value="<%=Integer.toString(totalCount)%>"></c:param>
					<c:param name="currentPageNo" value="<%=Integer.toString(currentPageNo)%>"></c:param>
					<c:param name="totalPageCount" value="<%= Integer.toString(totalPageCount)%>"></c:param>
				</c:import>
			</div>
		</div>
	</div>
</body>
</html>